import re

def extract_subtopics(text):
    # 找到“子主题”开头的位置
    start_index = text.find("子主题：")
    if start_index == -1:
        start_index = text.find("子主题:")
        if start_index == -1:
            return []
    # 获取从“子主题”开始的部分
    subtext = text[start_index:]
    text = text.strip().replace(' ', '')
    # 使用正则表达式匹配子主题
    pattern = re.compile(r'\*([^\n*]+)\n')
    subtopics = pattern.findall(subtext)
    return subtopics

def ExtSubTitle(content:str) -> list[str]:
    """
    提取文档的子主题列表
    """
    subtopics: list[str] = extract_subtopics(content)
    return [ item.strip() for item in subtopics ]

def ExtTitle(content:str) -> str:
    """
    提取文档的标题
    需要保证文档的标题位于文档的第一行
    """
    title = content.split('\n')[0].strip()
    return title

if __name__ == '__main__':
    # 读取文件内容
    file_path = '../input.txt'
    with open(file_path, 'r', encoding='utf-8') as file:
        content = file.read()
    # 提取子主题
    out = ExtSubTitle(content)
    print(out)
    out = ExtTitle(content)
    print(out)
 